package com.zrfintech.manage.controller.mg;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrfintech.common.pojo.BasePageEntity;
import com.zrfintech.domain.MgUser;
import com.zrfintech.manage.pojo.PageResponse;
import com.zrfintech.manage.service.MgUserService;
import com.zrfintech.manage.vo.request.UserRequest;
import com.zrfintech.service.MgUserRepo;
import com.zrfintech.service.MgUserRoleRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/webapi/user")
public class MgUserController {

    @Autowired
    private MgUserRepo mgUserRepo;

    @Autowired
    private MgUserRoleRepo mgUserRoleRepo;

    @Autowired
    private MgUserService mgUserService;

    @RequestMapping("/simpleList")
    public Object simpleList(BasePageEntity basePageEntity) {
        PageResponse<MgUser> pageResponse = new PageResponse<>();
        Page<MgUser> promotionUserPage = mgUserRepo.pageList(basePageEntity);
        pageResponse.setItems(promotionUserPage.getRecords());
        pageResponse.setTotal(promotionUserPage.getTotal());
        return pageResponse;
    }

    @RequestMapping("/upsert")
    public Object upsert(@RequestBody UserRequest userRequest) {
        mgUserService.upsert(userRequest, userRequest.getRoleCode());
        return new JSONObject();
    }
}
